﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using WPF_MVVM_Simple.Commands;
using WPF_MVVM_Simple.Model;

namespace WPF_MVVM_Simple.ViewModel
{
    /// <summary>
    /// MainWindow的ViewModel类
    /// 集合 请使用 ObservableCollection<MainViewModel>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        #region 控件 Binding
        private string _name = string.Empty;
        /// <summary>
        /// 名字
        /// </summary>
        public string Name
        {
            get => _name;
            set
            {
                _name = value;
                OnPropertyChanged("Name");  // 通知UI
            }
        }

        private string _email = string.Empty;
        /// <summary>
        /// 邮箱
        /// </summary>
        public string Email
        {
            get => _email;
            set
            {
                _email = value;
                OnPropertyChanged("Email");  // 通知UI
            }
        }

        private string _log = string.Empty;
        /// <summary>
        /// 打招呼的日志
        /// </summary>
        public string Log
        {
            get => _log;
            set
            {
                _log = value;
                OnPropertyChanged("Log");  // 通知UI
            }
        }
        #endregion 控件 Binding

        #region 控件事件
        /// <summary>
        /// 获取作者信息Command
        /// 数据流向：Model-> ViewModel-> View
        /// </summary>
        public ICommand ButtonCommand => new RelayCommand(
                    excute =>
                    {
                        // Model ->ViewModel
                        UserModel userModel = new UserModel()
                        {
                            ID = Guid.NewGuid().ToString("N"),
                            Name = "Bili执笔小白",
                            Email = "2806933146@qq.com"
                        };

                        #region 清空字符串（可省略）
                        Name = string.Empty;
                        Email = string.Empty;
                        Log = string.Empty;
                        #endregion 清空字符串（可省略）

                        Name = userModel.Name;
                        Email = userModel.Email;
                    },
                    canExcute => { return true; }
                );

        /// <summary>
        /// 和作者打招呼Command
        /// 数据流向：ViewModel-> View
        /// </summary>
        public ICommand Button1Command => new RelayCommand(
                    excute =>
                    {
                        Log = "你好！" + Name;
                    },
                    canExcute => { return true; }
                );
        #endregion 控件事件
    }
}